<div data-controller="reveal" data-reveal-hidden-class="hidden">
  <div class="custom-control custom-radio">
    <%= f.radio_button :kind, :coupon_code, data: { action: 'change->reveal#show' }, class: 'custom-control-input' %>
    <%= f.label :kind_coupon_code, Spree.t(:coupon_code), class: 'custom-control-label' %>

    <div data-reveal-target="item" class="rounded p-3 bg-light mt-3 <% if @promotion.automatic? %>hidden<% end %>">
      <div data-controller="reveal" data-reveal-hidden-class="hidden">
        <div class="d-flex align-items-start custom-control custom-radio">
          <%= f.radio_button :multi_codes, false, data: { action: 'change->reveal#toggle' }, class: 'custom-control-input' %>
          <%= f.label :multi_codes_false, class: 'custom-control-label' do %>
            One code for all customers
            <span class="form-text font-weight-normal mr-1 mt-2">
              You can limit the number of times this code can be used.
            </span>
          <% end %>
        </div>
        <div data-reveal-target="item" class="mb-4 mt-2 ml-4 <% if @promotion.multi_codes? %>hidden<% end %>">
          <%= f.text_field :code, class: 'form-control text-uppercase', placeholder: 'Your coupon code' %>
        </div>

        <div class="mt-2 d-flex align-items-start custom-control custom-radio">
          <%= f.radio_button :multi_codes, true, data: { action: 'change->reveal#toggle' }, class: 'custom-control-input' %>
          <%= f.label :multi_codes_true, class: 'custom-control-label' do %>
            Generate unique codes
            <span class="form-text font-weight-normal mr-1 mt-2">
              These codes are generated automatically and can be downloaded as a CSV file. Codes are unique and can only be used once.
            </span>
          <% end %>
        </div>
        <div data-reveal-target="item" class="ml-3 mt-2 row <% unless @promotion.multi_codes? %>hidden<% end %>">
          <div class="col-6">
            <%= f.text_field :code_prefix, class: 'form-control text-uppercase', placeholder: 'Coupon Prefix (optional)' %>
            <span class="form-text mt-2">
              eg. <strong>ABC</strong>
            </span>
          </div>
          <div class="col-6">
            <% minimum_number_of_codes = @promotion.persisted? && @promotion.coupon_codes.count.positive? ? @promotion.coupon_codes.count : 1 %>
            <% maximum_number_of_codes = ENV.fetch('PROMOTION_MAX_NUMBER_OF_CODES', 5000) %>
            <%= f.number_field :number_of_codes, class: 'form-control', placeholder: 'Number of codes', min: minimum_number_of_codes, max: maximum_number_of_codes, step: 1 %>
            <span class="form-text mt-2">
              How many codes you want to generate.
              <% if @promotion.persisted? %>
                To add more codes just increase this number
              <% end %>
            </span>
          </div>
        </div>
      </div>
    </div>
  </div>

  <div class="mt-4 custom-control custom-radio">
    <%= f.radio_button :kind, :automatic, data: { action: 'change->reveal#hide' }, class: 'custom-control-input' %>
    <%= f.label :kind_automatic, Spree.t(:automatic_promotion), class: 'custom-control-label' %>

    <p class="form-text mt-2 mb-0">
      This promotion will be automatically applied to all eligible orders.
    </p>
  </div>
</div>